/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Searchsupplier.java
 *
 * Created on Nov 20, 2011, 9:36:51 PM
 */
package introse;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.JOptionPane;
 import java.sql.*;
/**
 *
 * @author Owel
 */
public class Searchsupplier2 extends javax.swing.JFrame {
    private String id;
    private String name;
    private String Cate;
    private String iStock;
    private String pPric;
    private String sPric;
    private String sup;
    private String lmit;
    private String cate;
    /** Creates new form Searchsupplier */
    public Searchsupplier2() {
        initComponents();
          String data[][] = {{}};
        String col[] = {"SupplierId","SupplierName","Address","ContactNumber","Status"};
        DefaultTableModel model = new DefaultTableModel(data,col);
        jTable1.setModel(model);
        Statement s=null;
        ResultSet rs=null;
         try{
             Connect c = new Connect();
        Connection conn=c.dbConnect();
        s=conn.createStatement();
        String Sqls="SELECT * FROM supplier WHERE Status='Active'";
        rs=s.executeQuery(Sqls);
       while(rs.next())
       {
          System.out.println(rs.getString("SupplierId"));
          //rg.getString(column name);
         model.insertRow(jTable1.getRowCount()-1,new Object[]{rs.getString("SupplierId"),rs.getString("SupplierName"),rs.getString("ContactNumber"),rs.getString("Address"),rs.getString("Status")});
           
       }
       model.removeRow(jTable1.getRowCount());
        conn.close();
        }catch(Exception es){
          System.out.println(es);
            
        }
        
    }
 public Searchsupplier2(String pid,String supid,String namee,String limit,String pPrice,String sPrice,String category) { 
                initComponents();
          String data[][] = {{}};
        String col[] = {"SupplierId","SupplierName","Address","ContactNumber","Status"};
        DefaultTableModel model = new DefaultTableModel(data,col);
        jTable1.setModel(model);
        Statement s=null;
        ResultSet rs=null;
         try{
             Connect c = new Connect();
        Connection conn=c.dbConnect();
        s=conn.createStatement();
        String Sqls="SELECT * FROM supplier WHERE Status='Active'";
        rs=s.executeQuery(Sqls);
       while(rs.next())
       {
          System.out.println(rs.getString("SupplierId"));
          //rg.getString(column name);
         model.insertRow(jTable1.getRowCount()-1,new Object[]{rs.getString("SupplierId"),rs.getString("SupplierName"),rs.getString("ContactNumber"),rs.getString("Address"),rs.getString("Status")});
           
       }
       model.removeRow(jTable1.getRowCount()-1);
        conn.close();
        }catch(Exception es){
          System.out.println(es);
            
        }  
         id=pid;
         sup=supid;
         name=namee;
         lmit=limit;
         cate=category;
         pPric=pPrice;
         sPric=sPrice;
         }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel15 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        jButton15 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton23 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Search Supplier");
        setBounds(new java.awt.Rectangle(400, 125, 0, 0));

        jLabel15.setFont(new java.awt.Font("Verdana", 0, 14));
        jLabel15.setText("Search:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SupplierID", "SupplierName", "ContactNumber", "Address" }));

        jLabel16.setFont(new java.awt.Font("Verdana", 0, 14));
        jLabel16.setText(" by:");

        jButton15.setFont(new java.awt.Font("Verdana", 0, 12));
        jButton15.setText("Search");
        jButton15.setBorder(null);
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        jButton8.setFont(new java.awt.Font("Verdana", 0, 14));
        jButton8.setText("Select");
        jButton8.setBorder(null);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Verdana", 0, 18));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Search Supplier");
        jLabel1.setFocusable(false);
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1000001", "Peter Moleneuix", "Manila", "12335346"},
                {"1000002", "Job Gates", "Manila", "12455621"},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Supplier ID", "Name", "Address", "Contact Number"
            }
        ));
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jTable1);

        jButton23.setFont(new java.awt.Font("Verdana", 0, 12));
        jButton23.setText("View All");
        jButton23.setBorder(null);
        jButton23.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton23ActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jButton1.setText("Cancel");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                        .addGap(2, 2, 2)
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(73, 73, 73))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 765, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 745, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel16)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
// TODO add your handling code here:
    try{
     int row[]=jTable1.getSelectedRows();
        String supide=jTable1.getValueAt(row[0],0 ).toString();
        this.setVisible(false);
        EditProduct a=new EditProduct();
        a.Setsuppid(id,name,sup, lmit,pPric, sPric,cate);
        a.setVisible(true);
    }catch(Exception e){
        JOptionPane.showMessageDialog (null, "Please select from the table", "Error", JOptionPane.WARNING_MESSAGE);
    }
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton23ActionPerformed

      String data[][] = {{}};
        String col[] = {"SupplierId","SupplierName","Address","ContactNumber","Status"};
        DefaultTableModel model = new DefaultTableModel(data,col);
        jTable1.setModel(model);
        Statement s=null;
        ResultSet rs=null;
         try{
             Connect c = new Connect();
        Connection conn=c.dbConnect();
        s=conn.createStatement();
        String Sqls="SELECT * FROM supplier WHERE Status='Active'";
        rs=s.executeQuery(Sqls);
       while(rs.next())
       {
          System.out.println(rs.getString("SupplierId"));
          //rg.getString(column name);
         model.insertRow(jTable1.getRowCount()-1,new Object[]{rs.getString("SupplierId"),rs.getString("SupplierName"),rs.getString("ContactNumber"),rs.getString("Address"),rs.getString("Status")});
           
       }
       model.removeRow(jTable1.getRowCount()-1);
        conn.close();
        }catch(Exception es){
          System.out.println(es);
            
        }
}//GEN-LAST:event_jButton23ActionPerformed

private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
// TODO add your handling code here:
     String data[][] = {{}};
        String col[] = {"SupplierId","SupplierName","Address","ContactNumber","Status"};
        DefaultTableModel model = new DefaultTableModel(data,col);
        jTable1.setModel(model);
        Statement s=null;
        ResultSet rs=null;
         try{
             Connect c = new Connect();
        Connection conn=c.dbConnect();
        s=conn.createStatement();
        String Sqls="SELECT * FROM supplier WHERE "+jComboBox2.getSelectedItem().toString()+" LIKE '%"+jTextField3.getText()+"%' && Status='Active'";
        rs=s.executeQuery(Sqls);
       while(rs.next())
       {
          //rg.getString(column name);
         model.insertRow(jTable1.getRowCount()-1,new Object[]{rs.getString("SupplierId"),rs.getString("SupplierName"),rs.getString("ContactNumber"),rs.getString("Address"),rs.getString("Status")});
           
       }
       model.removeRow(jTable1.getRowCount()-1);
        conn.close();
        }catch(Exception es){
          System.out.println(es);
            
        }
}//GEN-LAST:event_jButton15ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    this.setVisible(false);
    
}//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Searchsupplier2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Searchsupplier2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Searchsupplier2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Searchsupplier2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Searchsupplier2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton23;
    private javax.swing.JButton jButton8;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
}
